package fm.dongman.animefm.view.util

import android.app.Activity
import android.app.ActivityOptions
import android.content.Intent

/**
 * activity 工具类
 * Created by shize on 2017/10/31.
 */
object ActivityHelper {
    /**
     * 启动 activity
     * @param activity activity
     * @param intent intent
     */
    fun startActivity(activity: Activity, intent: Intent) {
        // 添加自定义过渡动画
//        activity.startActivity(intent, ActivityOptions.makeSceneTransitionAnimation(activity).toBundle())
        activity.startActivity(intent)

    }

    /**
     * 关闭 activity
     * @param activity activity
     */
    fun backActivity(activity: Activity) {
        activity.onBackPressed()
    }

    /**
     * 启动 activity
     */
    fun startActivity(activity: Activity, target: Class<*>, map: Map<String, String>, isTransition: Boolean) {
        val intent = Intent(activity, target)
        map.forEach {
            intent.putExtra(it.key, it.value)
        }
        if (isTransition) {
            activity.startActivity(intent, ActivityOptions.makeSceneTransitionAnimation(activity).toBundle())
            return
        }
        activity.startActivity(intent)
    }
}